/**
 * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.opsli.modulars.business.gasWorkTask.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.opsli.api.wrapper.gasWorkTask.GasWorkTaskModel;
import org.opsli.modulars.business.gasWorkTask.entity.GasWorkTask;
import org.opsli.modulars.business.gasWorkTask.entity.GasWorkTaskData;
import org.opsli.modulars.business.gasWorkTask.mapper.GasWorkTaskMapper;
import org.opsli.modulars.business.gasWorkTask.service.IGasWorkTaskService;
import org.opsli.modulars.business.gasWorkTaskRecord.entity.GasWorkTaskRecord;
import org.opsli.modulars.business.gasWorkTaskRecord.mapper.GasWorkTaskRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.opsli.core.base.service.impl.CrudServiceImpl;

import java.util.Date;
import java.util.List;


/**
 * 燃气派单 Service Impl
 *
 * @author Ljc
 * @date 2022-07-14 16:35:26
 */
@Service
public class GasWorkTaskServiceImpl extends CrudServiceImpl<GasWorkTaskMapper, GasWorkTask, GasWorkTaskModel>
    implements IGasWorkTaskService {

    @Autowired(required = false)
    private GasWorkTaskMapper mapper;
    @Autowired(required = false)
    private GasWorkTaskRecordMapper recordMapper;

    @Override
    public Page<GasWorkTaskData> getGasWorkTaskList(Page<GasWorkTaskData> page, GasWorkTaskData gasWorkTaskData, Integer beginSize, Integer endSize) {


        List<GasWorkTaskData> list=mapper.getGasWorkTask(gasWorkTaskData);


        return page.setRecords(list);
    }

    @Override
    public Page<GasWorkTaskData> getGasWorkCommonList(Page<GasWorkTaskData> page, GasWorkTaskData gasWorkTaskData, Integer beginSize, Integer endSize) {

        List<GasWorkTaskData> list=mapper.getGasWorkCommon(gasWorkTaskData);

        return page.setRecords(list);
    }

    @Override
    public Page<GasWorkTaskData> gasWorkCheckList(Page<GasWorkTaskData> page, GasWorkTaskData gasWorkTaskData, Integer beginSize, Integer endSize) {

        List<GasWorkTaskData> list=mapper.getGasWorkCommon(gasWorkTaskData);


        return page.setRecords(list);
    }

    @Override
    public void getUpdateId(String id) {
        mapper.getUpdateId(id);
    }

    @Override
    public Integer getTaskReold(String id,String userId) {
        GasWorkTask task = mapper.getById(id);
        GasWorkTaskRecord recordModel = new GasWorkTaskRecord();
        if(null != task) {
            //先把原数据放到记录表里
            recordModel.setDevid(task.getDevid());
            recordModel.setDevname(task.getDevname());
            recordModel.setWorkId(task.getId());
            recordModel.setUserId(task.getUserId());
            recordModel.setUserName(task.getUserName());
            recordModel.setWorkType(task.getWorkType());
            recordModel.setBeginTime(task.getBeginTime());
            recordModel.setEndTime(task.getEndTime());
            recordModel.setFinishTime(task.getFinishTime());
            recordModel.setWorkUserName(task.getWorkUserName());
            recordModel.setWorkUserAddress(task.getWorkUserAddress());
            recordModel.setWorkUserPhone(task.getWorkUserPhone());
            recordModel.setWorkDescription(task.getWorkDescription());
            recordModel.setWorkState(task.getWorkState());
            recordModel.setWorkPic(task.getWorkPic());
            recordModel.setComment(task.getComment());
            recordModel.setReason(task.getReason());
            recordModel.setManager(task.getManager());
            recordModel.setCreateBy(userId);
            recordModel.setCreateTime(new Date());
            recordModel.setUpdateBy(userId);
            recordModel.setUpdateTime(new Date());
        }
        int a = recordMapper.insertSelective(recordModel);
        return 0;
    }

    @Override
    public GasWorkTaskData getByTaskId(String taskId) {
        return mapper.getByTaskId(taskId);
    }

}
